/**
 * index
 */
define(function(require) {
    var $ = require('jquery');
    var com = require('./common');


    Vue.filter('time', function (value) {
        function format(m) {
            return m < 10 ? '0' + m : m
        }
        var time = new Date(parseInt(value*1000));
        var y = time.getFullYear(),         //年
            m = time.getMonth() + 1,        //月
            d = time.getDate(),             //日
            H = time.getHours(),            //时
            i = time.getMinutes(),          //分
            s = time.getSeconds(),          //秒
            //当前时间
            date = new Date(),
            year = date.getFullYear(),      //当前年
            month = date.getMonth() + 1,    //当前月
            strDate = date.getDate();       //当前日
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
        return format(y) + '-' + format(m) + '-' + format(d)
    });


    var myapp = new Vue({
        el:'#myapp',
        data:{
            data:'',
            map:{
                rec_flag:0,
                kcmc:'',
                p:1,
                pagesize:20
            }
        },
        watch:{
            'map.kcmc':function(new_val,old_val){
                console.warn('新分类：'+ new_val);
                console.warn('旧分类：'+ old_val);
            }
        },
        methods:{
            change_flag:function(n){
                this.map.rec_flag = n;
                this.map.kcmc = ''
                this.initDate();
            },
            initDate:function(){
                var _this = this;
                //最新课程
                axios.get('/test/test4.json',{params:_this.map}).then(function(response){
                    var result = response.data;
                    _this.data = result.data;  //渲染数据
                });
            },
            teacherList:function(arr){
                var str = '';
                for(i in arr){
                    if(arr[i]['realname']){
                        if(i > 0){
                            str += '、';
                        }
                        str += arr[i]['realname'];
                    }
                }
                return str;
            },
            submitDate:function(){
                var _this = this;
                if(_this.map.kcmc == ''){
                    alert('请输入关键字！')
                    return false;
                };
                //提交数据
                axios.post('/test/test.json',_this.map).then(function(response){ 
                    //success callback
                    if(response.data.status == 0){
                        console.warn('提交成功');
                    };
                });
            }
        },
        created:function(){
            this.$nextTick(function(){
                this.initDate();
            })
        }
    });


    
});